package com.bb.Controllers;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.bb.pojo.User;
import com.bb.services.impl.UserServiceImpl;
import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class UserAction extends ActionSupport{
	/*定义接收的参数,使用属性传参数*/
	private String u_name;//接收的用户名登录用户名
	private String u_pass;//接收的用户名登录密码
	private User userupt;//用来接收修改的用户信息
	private int currentPage;//当前用户的页数
	private int rows;//每页显示的行数
	private Map dataMap;
	private UserServiceImpl userServiceImpl = new UserServiceImpl();
	private User user;
	private String u_id;
	/*添加数据*/
	public String insertAddUser(){
		int i = 0;
		i = new UserServiceImpl().addUser(userupt);
		if(i>0){
			return "addUser";
		}else{
			return "addUserError";
		}
	}
	/*调用删除的业务*/
	public String del(){
		int delUser = new UserServiceImpl().delUser(Integer.parseInt(u_id));
		return "delUser";
	}
	/*public String login(){
		System.out.println("用户登录");
		
		System.out.println("u_name:"+u_name+",u_pass:"+u_pass);
		User chkLogin = new UserServiceImpl().chkLogin(u_name);//根据接收的参数返回该数据
		if(chkLogin != null){
			如果查询的结果不为空 就把用户名存到session 里
			if(chkLogin.getU_pass().equals(u_pass)){
				Map<String, Object> session = ActionContext.getContext().getSession();
				session.put("username", chkLogin.getU_name());
				System.out.println("登录成功");
				return "loginSuccess";
			}else{
				return "loginError";
			}
		}else{
			return "loginError";
		}
		
	}*/
	//查询出所有的用户信息 用作首次登录成功跳到的首页面
	public String list(){
		Map map = new HashMap();
		if(currentPage == 0){
			currentPage=1;
		}
		if(rows == 0){
			rows = 5;
		}
		
		map.put("currentPage", currentPage);
		map.put("rows", rows);
		dataMap = userServiceImpl.getAllUser(map);
		return "list";
	}
	/*public String listT(){
		System.out.println("登录之后的用户列表");
		查询出所有的用户
		List<User> allUser = new UserServiceImpl().getAllUser();
		把所有的用户存到session里
		Map<String, Object> session = (Map<String, Object>) ActionContext.getContext().get("request");
		session.put("userList", allUser);
		System.out.println(allUser);
		return "listT";
	}*/
	//根据id查询出某一用户的具体信息
	public String selOne(){
		System.out.println("根据id查询出某一用户的具体信息");
		User oneUser = new UserServiceImpl().getOneUser(Integer.parseInt(u_id));
		System.out.println(oneUser);
		/*把用户信息存到request中用作转发*/
		ActionContext.getContext().put("user", oneUser);
		return "OneUser";
	}
	/*根据id显示用户要修改的信息*/
	public String selOneUpt(){
		System.out.println("根据id查询出某一用户要修改的具体信息");
		User oneUser = new UserServiceImpl().getOneUser(Integer.parseInt(u_id));
		System.out.println(oneUser);
		/*把用户信息存到request中用作转发*/
		ActionContext.getContext().put("user", oneUser);
		return "OneUserInfo";
	}
	/*处理用户的修改信息*/
	public String userUpdate(){
		System.out.println("处理用户的修改信息："+userupt);
		int i = 0;
		i = new UserServiceImpl().updateUser(userupt);
		System.out.println(i);
		return "updateUserSuccess";
	}
	public String getU_name() {
		return u_name;
	}
	public void setU_name(String u_name) {
		this.u_name = u_name;
	}
	public String getU_pass() {
		return u_pass;
	}
	public void setU_pass(String u_pass) {
		this.u_pass = u_pass;
	}
	public String getU_id() {
		return u_id;
	}
	public void setU_id(String u_id) {
		this.u_id = u_id;
	}
	public User getUserupt() {
		return userupt;
	}
	public void setUserupt(User userupt) {
		this.userupt = userupt;
	}
	/*@Override
	public String execute() throws Exception {
		// TODO Auto-generated method stub
		return null;
	}*/
	public User getUser() {
		return user;
	}
	public void setUser(User user) {
		this.user = user;
	}
	public int getCurrentPage() {
		return currentPage;
	}
	public void setCurrentPage(int currentPage) {
		this.currentPage = currentPage;
	}
	public int getRows() {
		return rows;
	}
	public void setRows(int rows) {
		this.rows = rows;
	}
	public Map getDataMap() {
		return dataMap;
	}
	public void setDataMap(Map dataMap) {
		this.dataMap = dataMap;
	}
	
}
